package cn.javaxc.mvcwork.controller;
import cn.javaxc.mvcwork.framework.actions.TActionContext;
import java.sql.*;
import java.util.*;
import javax.servlet.http.HttpSession;





public class UserSession {

  String id = null;
  int maxInactiveInterval = -1;
  long lastAccessed = -1;
  long creationTime = -1;
  String ipAddress = null;
  HashMap viewpoints = null;
  Object userId = -1;

  
  public UserSession() {
  }


  
  public UserSession(TActionContext context) {
    build(context);
  }


  
  public void setId(String id) {
    this.id = id;
  }


  
  public void setMaxInactiveInterval(int maxInactiveInterval) {
    this.maxInactiveInterval = maxInactiveInterval;
  }


  
  public void setLastAccessed(long lastAccessed) {
    this.lastAccessed = lastAccessed;
  }


  
  public void setIpAddress(String ipAddress) {
    this.ipAddress = ipAddress;
  }


  
  public void setCreationTime(long creationTime) {
    this.creationTime = creationTime;
  }


  
  public void setViewpoints(HashMap viewpoints) {
    this.viewpoints = viewpoints;
  }





  
  public long getCreationTime() {
    return creationTime;
  }


  
  public String getId() {
    return id;
  }


  
  public int getMaxInactiveInterval() {
    return maxInactiveInterval;
  }


  
  public long getLastAccessed() {
    return lastAccessed;
  }


  
  public String getIpAddress() {
    return ipAddress;
  }


  
  private void build(TActionContext context) {
    HttpSession session = context.getSession();
    id = session.getId();
    ipAddress = context.getIpAddress();
    creationTime = session.getCreationTime();
  }


  
  private void update(HttpSession session) {
    lastAccessed = session.getLastAccessedTime();
  }


  
  public void invalidateViewpoints() {
    viewpoints = null;
  }

  public Object getUserId() {
    return userId;
  }

  public void setUserId(Object userId) {
    this.userId = userId;
  }



  
  public boolean isViewpointsValid() {
    if (viewpoints == null) {
      return false;
    }
    return true;
  }
  public String toString(){
	return id;	
  }
}
